package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * 将1年级1班，改为"学前班"
 */
public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        try (
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true", "root", "root");
        ) {
            Statement statement = conn.createStatement();
            String sql = "UPDATE class SET name='学前班' WHERE name='1年级1班'";
            int num = statement.executeUpdate(sql);
            if(num>0){//说明至少影响了表中1条记录
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }
        }catch (Exception e){

        }
    }
}
